import {
	RouterMount,
	createRouter
} from 'uni-simple-router';
import store from './store/index.js'

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routes: [...ROUTES]
});

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	// 如果当前页面需要登录，且没有登录信息时，跳转到登录页
	if (to.meta.need_login && !store.state.user_info) {
		next({
			name: 'Login',
			NAVTYPE: 'push'
		})
	} else {
		next()
	}
});

// 全局路由后置守卫
// router.afterEach((to, from) => {
// })

export {
	router,
	RouterMount
}
